﻿$(document).ready(function () {
    $(".post-to").click(function (e) {
        e.preventDefault();
        $.post($(this).attr("href")).error(function (data) {
            addError("An error occured while processing your request.");
        });
    });

    $(".close-link").click(closeClick);

    $("#create-new-warning").click(function () {
        addWarning("Test");
    });
});

function closeClick(e) {
    e.preventDefault();
    $(this).parent().fadeOut(300, function () {
        $(this).remove();
    });
}

function addWarning(innerHtml) {
    var div = document.createElement("div");
    div.setAttribute("class", "alert-warning");
    var a = document.createElement("a");
    a.setAttribute("class", "close-link float-right");
    a.setAttribute("href", "#");
    a.innerHTML = "(Click to Dismiss)";
    div.innerHTML = innerHtml;
    div.appendChild(a);
    document.getElementById("alert-wrapper").appendChild(div);
    $(".close-link").click(closeClick);
}

function addError(innerHtml) {
    var div = document.createElement("div");
    div.setAttribute("class", "alert-error");
    var a = document.createElement("a");
    a.setAttribute("class", "close-link float-right");
    a.setAttribute("href", "#");
    a.innerHTML = "(Click to Dismiss)";
    div.innerHTML = innerHtml;
    div.appendChild(a);
    document.getElementById("alert-wrapper").appendChild(div);
    $(".close-link").click(closeClick);
}

function addInfo(innerHtml) {
    var div = document.createElement("div");
    div.setAttribute("class", "alert-info");
    var a = document.createElement("a");
    a.setAttribute("class", "close-link float-right");
    a.setAttribute("href", "#");
    a.innerHTML = "(Click to Dismiss)";
    div.innerHTML = innerHtml;
    div.appendChild(a);
    document.getElementById("alert-wrapper").appendChild(div);
    $(".close-link").click(closeClick);
}

function addSuccess(innerHtml) {
    var div = document.createElement("div");
    div.setAttribute("class", "alert-success");
    var a = document.createElement("a");
    a.setAttribute("class", "close-link float-right");
    a.setAttribute("href", "#");
    a.innerHTML = "(Click to Dismiss)";
    div.innerHTML = innerHtml;
    div.appendChild(a);
    document.getElementById("alert-wrapper").appendChild(div);
    $(".close-link").click(closeClick);
}